import React, { Component } from 'react';
import {View, Image, Block} from '@tarojs/components'
import {platform} from '../../../utils/platform-settting.service'
import {http} from '../../../utils/http'
import {
  CONTENT_PLAT_QR,
  GROUP_CONTENT
} from '../../../constants/api'
import {vcmonitor} from "../../../utils/tools";
import GzhAuth from "../../../components/gzh-auth/gzh-auth"
import {getContent} from "../../../utils/handlerPublicCode";
import './join.scss'

export default class Index extends Component {
  state: {
    imgUrl: string
    imgUrlDescribe: string
    platformInfo: false
    loading: any
    developContent: any
  } = {
    developContent: false,
    loading: true,
    imgUrl: '',
    imgUrlDescribe: '',
    platformInfo: false
  }

  async UNSAFE_componentWillMount() {
    let platformSet = platform.info
    if (!platform.isLoaded) {
      platformSet = (await platform.getSetting()) || platform.info
    }
    const { siteId = '' } = Taro.getCurrentInstance().router.params
    let developContent
    if (siteId) {
      developContent = await http.carGet(GROUP_CONTENT, {sid: siteId})
    } else {
      developContent = await http.carGet(GROUP_CONTENT)
    }
    const res = await http.HGet(CONTENT_PLAT_QR, {send_type: 7});
    this.setState({
      platformInfo: platformSet,
      developContent: developContent.content || '',
      loading: false,
      imgUrl: res.data.code,
      imgUrlDescribe: res.data.code_describe
    })
  }

  async componentDidShow() {
    vcmonitor(this)
  }

  render() {
    const {loading, developContent, platformInfo, imgUrl} = this.state
    return (
      <View className='join-us'>
        <GzhAuth />
        {!loading && <Block>
          {!developContent && <View>
            <View className='nickname' />
            <View className='welcome'>您的申请已经提交,</View>
            <View className='welcome'>请耐心等待</View>
            {imgUrl && imgUrl !== 'variable_code_close' && <View className='welcome'>长按识别扫码，查询审核结果</View>}
            {imgUrl && imgUrl !== 'variable_code_close' &&<View className='img-box'>
              <Image className='img' src={imgUrl} mode='aspectFit' />
            </View>}
          </View>}
          {platformInfo && platformInfo.platformName && !developContent && <View className='platform-name'>{platformInfo.platformName}</View>}
          {developContent && <Block>
            {process.env.TARO_ENV === "weapp" && <parser selectable html={developContent || ''} />}
            {process.env.TARO_ENV === "tt" && <rich-text preview selectable nodes={getContent(developContent)} />}
            {process.env.TARO_ENV === "h5" &&
            <View id='html-description' dangerouslySetInnerHTML={{__html: developContent}} />}
          </Block>}
        </Block>}
      </View>
    )
  }
}
